package com.lxyk.controller;

import com.lxyk.pojo.Dept;
import com.lxyk.pojo.Result;
import com.lxyk.service.DeptService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.concurrent.TimeUnit;

@RestController
@Slf4j
public class DeptController {
    @Autowired
    private DeptService deptService;

    @Value("${server.port}")
    private String serverPort;

    @GetMapping(value = "/dept/get/{id}")
    public Result<Dept> getByID(@PathVariable("id") Integer id){
        log.info("端口："+serverPort + "\t +dept/get/");

        try {
            TimeUnit.SECONDS.sleep(1);
            log.info("休眠1秒");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        Dept dept = deptService.queryByID(id);
        return new Result<>(200,"mysql-serverPort: "+serverPort,dept);
    }


    @GetMapping(value = "/dept/list")
    public Result<List<Dept>> list(){
        log.info("端口："+serverPort + "\t +dept/list/");

        List<Dept> deptList = deptService.query();

        return new Result<List<Dept>>(200,"mysql-serverPort: "+serverPort,deptList);
    }

}
